<?php
if($_GET['action']=="del")
{
	$sql = "select * from tb_order where id = '$_GET[id]'";
	$qr = select($sql);
	$rs = $qr[0];
	delete("tb_order","id='$rs[id]'");
	if(file_exists("../upload/$rs[document]")){
		@unlink("../upload/$rs[document]");
	}
	echo "<script>window.location='admin.php?mode=order_list.php'</script>";
}
////active //////
switch($_GET[approve]){

	case"online";
		$data=array("active"=>(0),);	
		update("tb_order",$data,"id=$_GET[id]");
		echo "<script>window.location='admin.php?mode=order_list.php'</script>";
		
	break;
		case"offline";
		$data=array("active"=>(1),);
		update("tb_order",$data,"id=$_GET[id]");
		echo "<script>window.location='admin.php?mode=order_list.php'</script>";
		
	break;
	}
//// end active/////
$page = (isset($_GET['page']))? intval($_GET['page']) : 1;
$limit_end = 20;
$limit_start = ($page-1)*$limit_end;

$send = "mode=order_list.php";
$sql = "SELECT * FROM tb_order order by id desc" ;

$qr=select($sql. " LIMIT " . $limit_start. "," . $limit_end); 
$total=count($qr);
$rows = mysql_num_rows(mysql_query($sql));
$i=0;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title></head>

<body>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="15" align="left" class="headmenu"><img src="image/bar_left.gif" width="15" height="42" /></td>
    <td align="left" bgcolor="#434343" class="headmenu">รายการสั่งซื้อ</td>
    <td width="15" align="left" class="headmenu"><img src="image/bar_right.gif" width="15" height="42" /></td>
  </tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:20px;">
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td width="53" align="center" bgcolor="#434343" class="headmenu" ><strong>ลำดับ</strong></td>
    <td align="center" bgcolor="#434343" class="headmenu" ><strong>เลขที่ใบสั่งซื้อ</strong></td>
    <td align="center" bgcolor="#434343" class="headmenu" ><strong>ชื่อผู้สั่งซื้อ</strong></td>
    <td width="80" align="center" bgcolor="#434343" class="headmenu" ><strong>เบอร์โทร</strong></td>
    <td width="80" align="center" bgcolor="#434343" class="headmenu" ><strong>Email</strong></td>
    <td width="80" align="center" bgcolor="#434343" class="headmenu" ><strong>วันที่สมัคร</strong></td>
    <td width="108" align="center" bgcolor="#434343" class="headmenu" ><strong>ลบ</strong></td>
  </tr>
<?php
  
if($total > 0){ 
	while($i<count($qr)){ 
	$rs=$qr[$i];
  	if($bg == "#FFFFFF"){$bg = "#FFFFCC";}else{$bg = "#FFFFFF";}
?>
  <tr bgcolor="<?=$bg;?>">
    <td align="center" class="darkgray13" ><?=$i+1;?></td>
    <td align="center" bgcolor="<?=$bg;?>" class="darkgray13"><a class="darkgray13"  href="buy_detail.php?id=<?php echo $rs['id'] ?>" onclick="NewWindow(this.href,'Image Manager','900','700','yes','center');return false" onfocus="this.blur()"><?php echo $rs['invoice'] ?></a></td>
    <td align="center" class="darkgray13"><?=$rs['name'];?></td>
    <td align="center" class="darkgray13"><?=$rs[tel];?></td>
    <td align="center" class="darkgray13"><?=$rs['email']?></td>
    <td align="center" class="darkgray13"><?php echo DateThai($rs['order_date'])?></td>
    <td align="center" valign="middle"><a onClick="return confirm('ต้องการจะลบข้อมูล?')" href="admin.php?mode=order_list.php&amp;id=<?=$rs[id]?>&action=del"><img src="image/delete.png"border="0" title="ลบ" /></a> </td>
  </tr>
  <?php 
  $i++;
	}//end while//
}//end if($total > 0)//
  ?>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><?php if(($rows/$limit_end) > 1){ 
		echo "\n<div>" . page_navi($page, $limit_end, 4, $rows, $send,"mynavic","mynavi") . " </div>";
	}?></td>
  </tr>
</table>


</body>
</html>
